package org.poem.payment.controller;


import cn.hutool.core.date.DateUtil;
import org.poem.common.response.CommonResult;
import org.poem.payment.entity.Payment;
import org.poem.payment.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.client.RestTemplate;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author poem
 * @since 2021-04-05
 */
@RestController
@RequestMapping("/v1/payment")
public class PaymentController {


    @Autowired
    private IPaymentService paymentService;

    @Value("${server.port}")
    private Integer port;

    @GetMapping("/getFeignInterface")
    public CommonResult<String> getFeignInterface(){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new CommonResult<String>(port + "   " + DateUtil.formatDateTime(new Date()));
    }
    /**
     * 保存
     * @param payment
     * @return
     */
    @PostMapping("/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        this.paymentService.create(payment);
        return new CommonResult<Payment>(payment);
    }

}

